<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="https://www.thymeleaf.org">
<head>
    <title>PS游戏管理</title>
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link th:href="@{/css/bootstrap.css}" rel="stylesheet" media="all">
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" media="all">
    <script th:src="@{/js/jquery-3.6.0.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>
    <script th:src="@{/layui/layui.js}"></script>
</head>
<script>
    function updateValues(ID){
        $("#UpdateID").val(ID);
    }
    function deleteValues(ID){
        $("#DeleteID").val(ID);
    }
    function SearchPType() {
        var type = $("#typeSearch").val();
        data = {
            type: type
        }
        $.ajax({
            url: "searchPType",
            type: "Post",
            data: data,
            datatype: "html",
            success: function (data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function namePSearch() {
        var name = $("#namePSearch").val();
        data = {
            name: name
        }
        $.ajax({
            url: "selectPName",
            type: "Post",
            data: data,
            datatype: "html",
            success: function (data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function AddPsGame(){
        var name = $("#AddName").val();
        var introduction = $("#AddIntroduction").val();
        var yuyan = $("#AddYuyan").val();
        var type = $("#AddType").val();
        var score = $("#AddScore").val();
        data = {
            name:name,
            introduction:introduction,
            yuyan:yuyan,
            type:type,
            score:score,
        }
        $.ajax({
            url:"psgame/insertPsGame",
            type: "Post",
            data:data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
    function WatchPPhoto(ID) {
        data = {
            id: ID
        }
        $.ajax({
            url:"/psgame/watchPPhoto",
            type: "Post",
            data:data,
            datatype: "html",
            success: function(data, status) {
                $("#PSG").replaceWith(data);
            }
        })
    }
    function UpdatePsGame(){
        var id = $("#UpdateID").val();
        var yuyan = $("#UpdateYuyan").val();
        var score = $("#UpdateScore").val();
        if(score == "")  score = 0;
        data = {
            id: id,
            yuyan:yuyan,
            score:score,
        }
        $.ajax({
            url:"psgame/updatePsGame",
            type: "Post",
            data:data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
    function DeletePsGame(){
        var id = $("#DeleteID").val();
        data = {
            id: id
        }
        $.ajax({
            url:"psgame/deletePsGame",
            type: "Post",
            data:data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
</script>
<body>
<div class="container mt-3" id="roomInformation">
    <h2>PS游戏管理界面</h2>
    <br>
    <ul class="nav nav-pills" role="tablist">
        <li class="navbar-form navbar-left" role="search">
            <a class="form-group">
                <input type="text" class="form-control" id="namePSearch" placeholder="搜索名称"/>
            </a>
        </li>
        <li><button type="submit" class="btn btn-default" onclick="namePSearch()">搜索</button></li>
        <div class="selecttype">
            <select id="typeSearch" type="button" onchange="SearchPType()" class="btn btn-light btn-sm">
                <option>游戏类型</option>
                <option value="all">全部类型</option>
                <option value="角色扮演">角色扮演</option>
                <option value="动作游戏">动作游戏</option>
                <option value="冒险游戏">冒险游戏</option>
                <option value="策略游戏">策略游戏</option>
            </select>
        </div>
        <li class="pagination"><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#add">添加PS游戏</button></li>

    </ul>

    <div class="tab-content">
        <div id="home" class="container tab-pane active"><br>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>游戏号</th>
                    <th>游戏名称</th>
                    <th style="width: 444px">游戏介绍</th>
                    <th>语言</th>
                    <th>类型</th>
                    <th>评分</th>
                    <th>图片</th>
                    <th>修改</th>
                    <th>删除</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="psgame:${psGames}">
                    <td th:text="${psgame.id}"></td>
                    <td th:text="${psgame.name}"></td>
                    <td th:text="${psgame.introduction}"></td>
                    <td th:text="${psgame.yuyan}"></td>
                    <td th:text="${psgame.type}"></td>
                    <td th:text="${psgame.score}"></td>
                    <td><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#photo" th:onclick="|javascript:WatchPPhoto('${psgame.id}')|">查看</button></td>
                    <td><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#modify" th:onclick="|javascript:updateValues('${psgame.id}')|">修改</button> </td>
                    <td><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#fire" th:onclick="|javascript:deleteValues('${psgame.id}')|">删除</button> </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="modal picture" id="photo">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">PS游戏图片</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal" onclick="location.reload()"></button>
            </div>

            <div class="modal-body" id="PSG">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal"onclick="location.reload()">关闭</button>
            </div>

        </div>
    </div>
</div>

<div class="modal Add" id="add">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <div class="modal-header">
                <h3 class="modal-title">PS游戏信息</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <tbody>
                    <tr>
                        <td style="font-size:22px">游戏名称</td><td><input id="AddName" name="AddName" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">游戏介绍</td><td><input id="AddIntroduction" name="AddIntroduction" style="height:32px;width:100%;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">语言版本</td><td><input id="AddYuyan" name="AddYuyan" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">游戏类型</td><td><input id="AddType" name="AddType" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">游戏评分</td><td><input id="AddScore" name="AddScore" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="AddPsGame()">确定</button>
            </div>

        </div>
    </div>
</div>

<div class="modal alter" id="modify">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h4 class="modal-title">PS游戏信息</h4>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">游戏号</td><td><input readonly="readonly" id="UpdateID" name="UpdateID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">语言版本</td><td><input id="UpdateYuyan" name="UpdateYuyan"  style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">游戏评分</td><td><input id="UpdateScore" name="UpdateScore"  style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="UpdatePsGame()">确定</button>
            </div>

        </div>
    </div>
</div>

<div class="modal Fire" id="fire">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">删除PS游戏</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">游戏号</td><td><input readonly="readonly" id="DeleteID" name="DeleteID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">是否删除该游戏？</td><td style="height:32px;width:300px;font-size:22px">永久删除该游戏（真的很久）</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="DeletePsGame()">是</button>
            </div>

        </div>
    </div>
</div>

</body>
</html>